/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.data.dao;

import cn.ekuma.data.dao.bean.CreateDateAble;
import cn.ekuma.data.dao.bean.ModifiedLogAble;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.StaticSentence;

import java.util.Date;
import java.util.List;

/**
 *
 * @author Administrator
 */
public abstract class ModifiedLogDAO<T extends ModifiedLogAble>  extends BaseDAO<T> implements I_DataTimeListSuport{

    public ModifiedLogDAO(I_Session s) {
        super(s);
    }

    @Override
    public void befareUpdate(T t) throws BasicException{
        super.befareUpdate(t);
        if(t instanceof ModifiedLogAble)
            ((ModifiedLogAble)t).setLastModified(new Date());
    }

    @Override
    public void befareInsert(T t) throws BasicException{
        super.befareInsert(t);
        if(t instanceof ModifiedLogAble)
            ((ModifiedLogAble)t).setLastModified(new Date());
        if(t instanceof CreateDateAble)
        	((CreateDateAble)t).setCreateDate(new Date());
    }

	@Override
	public List listWithTime(Date start, Date end) throws BasicException {
		String sql =getTable().getListSQL(start, end);
        return new StaticSentence(getTable().getM_s(), sql,null,this).list();
	}
 
}
